package com.letwal.cmcvnd.assetdetail

import android.annotation.SuppressLint
import android.view.View
import androidx.core.content.ContextCompat
import androidx.lifecycle.ViewModel
import com.letwal.cmcvnd.R
import com.letwal.cmcvnd.assetdetail.repo.AssetDetailRepo
import com.letwal.cmcvnd.base.BaseActivity
import com.letwal.cmcvnd.enums.PageTagEnum
import com.letwal.cmcvnd.extend.*
import com.letwal.cmcvnd.databinding.ActivityAssetDetailResultBinding

/** asset详情页 */
@SuppressLint("CustomSplashScreen")
class AssetDetailResultActivity : BaseActivity() {

    //布局binding
    private lateinit var mActivityBinding: ActivityAssetDetailResultBinding

    override fun onBindingViewModel(): List<ViewModel> {
        val list = mutableListOf<ViewModel>()
        return list
    }

    override fun onBindingViewTag(): String {
        return PageTagEnum.my_wallet.name.uppercase()
    }

    override fun onBindingContentView(): View {
        mActivityBinding =
            ActivityAssetDetailResultBinding.inflate(layoutInflater)
        return mActivityBinding.root
    }

    @SuppressLint("SetTextI18n")
    override fun onContentViewBinded() {
        try {
            AssetDetailRepo.mMyTransactions?.let {
                mActivityBinding.textAssetDetailResultDate.text = it.createTime
                mActivityBinding.textAssetDetailResultTxIDValue.text = it.txid
                mActivityBinding.textAssetDetailResultReceiveTips.text = it.symbol

                if (it.status.contains("fail", true)) {
                    mActivityBinding.textStatus.text = getString(R.string.asset_detail_failure)
                    mActivityBinding.textStatus.setTextColor(
                        ContextCompat.getColor(
                            this,
                            R.color.main_red
                        )
                    )
                    mActivityBinding.imageStatus.setImageResource(R.drawable.icon_failure)
                    mActivityBinding.imageAssetDetailResultReceiveTips.setImageResource(R.drawable.icon_failure)

                } else if (it.status.contains("succe", true)) {
                    mActivityBinding.textStatus.text = getString(R.string.asset_detail_successful)
                    mActivityBinding.textStatus.setTextColor(
                        ContextCompat.getColor(
                            this,
                            R.color.main_green
                        )
                    )
                    mActivityBinding.imageStatus.setImageResource(R.drawable.icon_success)
                    mActivityBinding.imageAssetDetailResultReceiveTips.setImageResource(R.drawable.icon_success)

                } else if (it.status.contains("process", true)) {
                    mActivityBinding.textStatus.text = getString(R.string.withdraw_status_processing)
                    mActivityBinding.textStatus.setTextColor(
                        ContextCompat.getColor(
                            this,
                            R.color.main_green
                        )
                    )
                    mActivityBinding.imageStatus.setImageResource(R.drawable.icon_processing)
                    mActivityBinding.imageAssetDetailResultReceiveTips.setImageResource(R.drawable.icon_processing)

                } else if (it.status.contains("create", true)) {
                    mActivityBinding.textStatus.text = getString(R.string.withdraw_status_processing)
                    mActivityBinding.textStatus.setTextColor(
                        ContextCompat.getColor(
                            this,
                            R.color.main_green
                        )
                    )
                    mActivityBinding.imageStatus.setImageResource(R.drawable.icon_processing)
                    mActivityBinding.imageAssetDetailResultReceiveTips.setImageResource(R.drawable.icon_processing)
                }


                if (it.inOrOut.equals("out", true)) {
                    mActivityBinding.textAssetDetailResultReceive.text =
                        getString(R.string.transations_out)

                    mActivityBinding.textAssetDetailResultReceiveAmount.text = "- " + it.amount

                    mActivityBinding.textAssetDetailResultToValue.text = it.address
                    mActivityBinding.rlAssetDetailResultFrom.visibility = View.GONE

                } else {
                    mActivityBinding.textAssetDetailResultReceive.text =
                        getString(R.string.transations_receive)

                    mActivityBinding.textAssetDetailResultReceiveAmount.text = "+ " + it.amount

                    mActivityBinding.textAssetDetailResultFromValue.text = it.address
                    mActivityBinding.rlAssetDetailResultTo.visibility = View.GONE
                }
            }
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }
}